package com.it.ymcc.controller;

import com.it.ymcc.entity.JSONResult;
import com.it.ymcc.entity.Role;
import com.it.ymcc.entity.User;
import com.it.ymcc.service.IRoleService;
import com.it.ymcc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/role")
@RestController
public class RoleController {
    @Autowired
    public IRoleService roleService;

    /**
     * 保存和修改公用的
     */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JSONResult saveOrUpdate(@RequestBody Role role){
        if(role.getId()!=null){
            roleService.updateById(role);
        }else{
            roleService.insert(role);
        }
        return JSONResult.success();
    }

    /**
     * 删除对象
     */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JSONResult delete(@PathVariable("id") Long id){
        roleService.deleteById(id);
        return JSONResult.success();
    }

    /**
     * 获取对象
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(roleService.selectById(id));
    }


    /**
     * 查询所有对象
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JSONResult list(){
        return JSONResult.success(roleService.selectList(null));
    }
}
